<?php
declare (strict_types=1);

namespace app\api\controller\v1;

use app\api\helpers\v1\traits\SearchDataForModel;
use app\api\model\v1\AdminLog;
use app\api\model\v1\Admins;
use app\BaseController;
use think\Request;

class Log extends BaseController
{
    use SearchDataForModel;

    /**
     * @User: 刘海龙
     * @Date: 2021/9/28
     * @Time: 15:12
     * @return \think\response\Json
     * @throws \think\db\exception\DbException
     * 获取日志
     */
    public function getAdminLogList()
    {
        $limit = $this->request->param('limit', 10);
        $map = [];
        $map[] = array('admin_id', 'in', $this->childrenAdminIds);
        $res = $this->search(new AdminLog(), $map, $limit);
        return $this->response($res);
    }


    /**
     * @User: 刘海龙
     * @Date: 2021/9/28
     * @Time: 15:35
     * @return \think\response\Json
     * 更新用户信息
     */
    public function updatePersonalData()
    {
        $data = $this->request->param();
        $data['id'] = $this->request->uid;
        if (empty($data['password'])) {
            unset($data['password']);
        } else {
            $data['password'] = password_hash($data['password'], PASSWORD_DEFAULT);
        }
        Admins::update($data);
        AdminLog::record('更新用户信息', $this->request->param(), $this->request->uid, $this->request->username);
        return $this->response();
    }
}
